博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用GitHub作Free图床
阅读量:4353 次
发布时间:2019-06-07

本文共 2035 字,大约阅读时间需要 6 分钟。

一、方法原理

  1、使用GitHub的Issues问题功能。

  新建一个Issues问题请求

  将图片拖拉或者上传到问题框后,会返回一个地址,这个地址就是图片直链

  

  2、通过访问github仓库内的图片地址并进行修改

例如我的image-host仓库,地址是:https://github.com/wangchuanli001/image-host/tree/master/imgtemp

对于对应的图片,例如,

https://github.com/wangchuanli001/image-host/blob/master/imgtemp/snowtree.jpg(原地址)

进行更改后(可以作为直链访问):

https://github.com/wangchuanli001/image-host/blob/master/imgtemp/snowtree.jpg?raw=true

https://github.com/wangchuanli001/image-host/raw/master/imgtemp/snowtree.jpg

 

 二、拓展

  对于图片的上传只要记录下上传的文件路径以及文件名,就可以免费使用github作为图床使用了。

   1、通过爬虫进行爬取github上的内容,进行截取和拼接形成图片直链

    这个Python爬虫有编码问题,即gbk编码问题

import reimport urllib.requestfrom bs4 import BeautifulSoupurl = "https://github.com/wangchuanli001/image-host/tree/master/imgtemp"def getdoc():    html_doc = urllib.request.urlopen(url).read()    f = open("doc.txt","wb")    f.write(html_doc)    f.close()def test():    f = open("doc.txt","rb+")    s = f.read()    soup = BeautifulSoup(s,"html.parser",from_encoding="GB18030")    print ("start")    links = soup.select('a')    for link in links:        print (link)    f.close()

  2、通过图片上传工具进行记录

    记录本地文件路径和文件名,上传后生成直链。

import os# 从本地clone的仓库中得到文件列表def fileListFunc(fileList,filePath,suffix):    for filename in os.listdir(filePath):        if os.path.isdir((filePath+"/"+filename)):            # print (filePath+"/"+filename)            fileListFunc(fileList,(filePath+"/"+filename),suffix)        else:            if filename.endswith(suffix):                fileList.append(filePath+"/"+filename)    return fileList# 对列表中的文件进行字符串拼接成图片链接def listHandler(fileList,filePath):    for i in range(0,len(fileList)):        fileList[i] = ""    fileList.append("-----------------------")# 将图片链接追加到md文件的最后def list2md(fileList):    fo = open("image.md","a+")    for item in fileList:        fo.write(item)    fo.close()fileList = []filePath = "E:\GitHub\Respositories\image-host"fileLists = fileListFunc(fileList,filePath,"jpg")listHandler(fileLists,filePath)print (fileLists)list2md(fileLists)

 

转载于:https://www.cnblogs.com/null-/p/10051036.html

你可能感兴趣的文章
修改ip脚本
查看>>
解析xlsx与xls--使用2012poi.jar
查看>>
java5,java6新特性
查看>>
【LOJ】#2290. 「THUWC 2017」随机二分图
查看>>
SSL-ZYC 活动安排
查看>>
Git clone 报错 128
查看>>
在Python中执行普通除法
查看>>
编译原理(第三版) 语法分析器
查看>>
c# 动态绘制直线和曲线
查看>>
Spring理解?
查看>>
删除无限循环的文件夹-删除递归文件夹
查看>>
Test
查看>>
C# 整理
查看>>
AngularJS中使用$resource
查看>>
[poj3261]Milk Patterns(后缀数组)
查看>>
[luogu3369]普通平衡树(fhq-treap模板)
查看>>
题解 P2799 【国王的魔镜】
查看>>
写写代码,注意注意细节
查看>>
css Backgroud-clip (文字颜色渐变)
查看>>
安装 OpenSSL 工具
查看>>